#pragma once

#include "base_noncopyable.h"
#include "upgrade.h"
#include <string>
#include <functional>

namespace El {
namespace Restful {

// 系统管理实现类
class SystemManager {
    DISALLOW_COPY_AND_MOVE(SystemManager);

public:
    static SystemManager &GetInstance();

    bool RestartDevice(int delay = 0, bool force = false);
    bool UpdateFirmware(const std::string &firmware_path);

    // 固件升级相关接口实现
    bool InitializeUpgrade(const std::string &filename,
                           size_t filesize,
                           const std::string &version,
                           const std::string &md5,
                           int total_chunks);

    bool HandleChunkData(const std::string &chunk_data_base64, int chunk_index, int total_chunks);

    // 开始升级过程
    bool StartUpgradeProcess();

    El::Upgrade::UpgradeStatus GetUpgradeStatus() const
    {
        return upgrade_status_;
    }

    int GetUpgradeProgress() const
    {
        return upgrade_progress_;
    }

    std::string GetUpgradeMessage() const
    {
        return upgrade_message_;
    }

private:
    SystemManager() = default;

    // 设置升级状态和消息
    void SetUpgradeStatus(El::Upgrade::UpgradeStatus status, const std::string &message);

private:
    // 升级相关状态
    int upgrade_progress_ = 0;
    El::Upgrade::UpgradeStatus upgrade_status_ = El::Upgrade::UpgradeStatus::IDLE;
    std::string upgrade_message_;
    std::string current_file_;
    size_t total_chunks_ = 0;
    size_t received_chunks_ = 0;
    std::string file_md5_;
};

} // namespace Restful
} // namespace El